package main

import "fmt"

func writeData(initChan chan int) {
	for i := 1; i <= 50; i++ {
		initChan <- i
		fmt.Printf("writeData 写到数据=%v\n", i)
	}
	close(initChan)
}
func readData(initChan chan int, exitChan chan bool) {
	for {
		v, ok := <-initChan
		if !ok {
			break
		}
		fmt.Printf("readData 读到数据=%v\n", v)
	}
	exitChan <- true
	close(exitChan)

}
func main() {
	initChan := make(chan int, 50)
	exitChan := make(chan bool, 1)
	go writeData(initChan)
	go readData(initChan, exitChan)
	for {
		_, ok := <-exitChan
		if !ok {
			break
		}
	}

}
